home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / CGX.asm < prev    next >
Encoding:
Assembly Source File  |  2000-07-21  |  7.7 KB  |  448 lines

  1. ; CGX-Direct driver (need 352x262 8 bit screen)
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.1
  6. ; 1.2: added MODULO support (08.07.99)
  7. ; 1.3: added config support (12.07.99)
  8. ; 1.4: version level change (21.07.00 by Rachy)
  9.  
  10. TRUE    equ    1
  11. FALSE    equ    0
  12.  
  13.         INCDIR    Include:
  14.  
  15.     INCLUDE exec/types.i
  16.     INCLUDE    exec/memory.i
  17.     INCLUDE    exec/exec_lib.i
  18.     INCLUDE    utility/tagitem.i
  19.     INCLUDE    intuition/intuition.i
  20.     INCLUDE    intuition/intuition_lib.i
  21.     INCLUDE    intuition/screens.i
  22.     INCLUDE graphics/modeid.i
  23.     INCLUDE    graphics/rastport.i
  24.     INCLUDE    libraries/cybergraphics_lib.i
  25.     INCLUDE    cybergraphics/cybergraphics.i
  26.     INCLUDE    dos/dos_lib.i
  27.     INCLUDE    dos/dostags.i
  28.     INCLUDE    dos/dosextens.i
  29.     INCLUDE    dos/var.i
  30.  
  31.  
  32.  
  33. ;*** Handler structure
  34.  
  35.  STRUCTURE vxd_handler,0
  36.  
  37.   LONG intuibase
  38.   LONG dosbase
  39.   LONG myscr
  40.   LONG mywin
  41.   LONG planes
  42.   WORD xsize
  43.   WORD ysize
  44.   LONG palette
  45.   LONG palette32
  46.   LONG emuscr
  47.   WORD bytesperrow
  48.   LONG cybbase
  49.   LONG screendim
  50.  LABEL    vxd_handler_SIZEOF
  51.  
  52.  
  53. JSRLIB    MACRO
  54.     jsr    _LVO\1(a6)
  55.     ENDM
  56.  
  57. ;*** Let's begin
  58.  
  59.     moveq.l    #0,d0
  60.     rts
  61.  
  62.     dc.b "FLAMINGOXVD"
  63.     dc.b "2"
  64.  
  65.     dc.l Name
  66.     dc.l Author
  67.     dc.w 1
  68.     dc.w 4
  69.  
  70.     dc.l drv_Init
  71.     dc.l drv_Done
  72.     dc.l drv_Configure
  73.     dc.l drv_OpenScreen
  74.     dc.l drv_CloseScreen
  75.     dc.l drv_Refresh
  76.     dc.l 0            ;No PPC refresh
  77.  
  78. Name:    dc.b    "CGX-Direct External Video Driver 1.4 (21.07.00)",0
  79. Author:    dc.b    "László (pH03N1x) Török",0
  80.  
  81.     EVEN
  82.  
  83. ;*** Functions
  84.  
  85. drv_Init:
  86.     movem.l    a0-a1,-(sp)    ;Saving infos
  87.     move.l  4.w,a6        ;Alloc memory for handler
  88.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  89.     move.l    #vxd_handler_SIZEOF,d0
  90.     JSRLIB    AllocVec
  91.     movem.l    (sp)+,a0-a1    ;Recover infos
  92.         tst.l    d0
  93.     beq.b    b1        ;No mem
  94.     movea.l    d0,a2
  95.  
  96.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  97.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  98.  
  99.         movem.l    d0,-(sp)
  100.     move.l    dosbase(a2),a6        ;Reading config file
  101.     move.l    #configfile,d1        ;Config file is pretty simple:
  102.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  103.     JSRLIB    Open
  104.     tst.l    d0
  105.     beq.b    .2            ;Failed open
  106.     move.l    d0,d1
  107.     move.l    (sp),a0
  108.     lea    screendim(a0),a0
  109.     move.l    a0,d2
  110.     moveq.l    #4,d3
  111.     movem.l    d0,-(sp)
  112.     JSRLIB    Read            ;Reading the 4 bytes
  113.     cmp.l    #4,d0
  114.     beq.b    .3
  115.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  116.     move.l    #0,screendim(a0)
  117.  
  118. .3    movem.l    (sp)+,d1
  119.     JSRLIB    Close
  120.  
  121. .2    movem.l    (sp)+,d0
  122.  
  123. b1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  124.     rts                ;Result in D0 available for now
  125.  
  126. drv_Done:
  127.     movea.l    a0,a1
  128.     cmp.l    #0,a1
  129.     beq.b    c1
  130.     move.l    4.w,a6
  131.     JSRLIB    FreeVec        ;Deallocate handler
  132. c1
  133.     rts
  134.  
  135.  
  136. drv_Configure:            ;Configure
  137.                 ;A simple screenmode requester appears
  138.     movem.l    a0,-(sp)
  139.  
  140.     move.l    a0,a5
  141.     move.l    screendim(a5),ScrDisplayID
  142.  
  143.     moveq    #$00,d0
  144.     moveq    #$00,d1
  145.     move.w    xsize(a5),d0
  146.     move.w    ysize(a5),d1
  147.  
  148.     move.l    d0,cgfxmodewidth
  149.     move.l    d1,cgfxmodeheight
  150.  
  151.     move.l    4.w,a6
  152.     lea    cyblib(pc),a1
  153.     moveq    #40,d0
  154.     jsr    _LVOOpenLibrary(a6)
  155.     move.l    d0,cybbase(a5)
  156.     beq.b    configbug
  157.  
  158.     move.l    cybbase(a5),a6
  159.     lea    cybreqtags(pc),a1
  160.     jsr    _LVOCModeRequestTagList(a6)
  161.  
  162.     cmp.l    #INVALID_ID,d0
  163.     bne.b    config2
  164.  
  165.     move.l    (4).w,a6
  166.     move.l    cybbase(a5),a1
  167.     jsr    _LVOCloseLibrary(a6)
  168.     clr.l    cybbase(a5)
  169.  
  170. configbug:
  171.     suba.l    a0,a0
  172.     move.l    intuibase(a5),a6
  173.     jsr    _LVODisplayBeep(a6)
  174.     lea    4(sp),sp
  175.     rts
  176.  
  177. config2:
  178.     move.l    d0,screendim(a5)
  179.     
  180.     move.l    dosbase(a5),a6        ;Writing config file
  181.     move.l    #configfile,d1        ;Config file is pretty simple:
  182.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  183.     JSRLIB    Open
  184.     tst.l    d0
  185.     beq.b    .1            ;Failed open
  186.     move.l    d0,d1
  187.     move.l    (sp),a0
  188.     lea    screendim(a0),a0
  189.     move.l    a0,d2
  190.     moveq.l    #4,d3
  191.     movem.l    d0,-(sp)
  192.     JSRLIB    Write            ;Writing the 4 bytes
  193.  
  194.     movem.l    (sp)+,d1        ;We don't care too much on
  195.     JSRLIB    Close            ;success...
  196.  
  197. .1
  198.     move.l    (4).w,a6
  199.     move.l    cybbase(a5),a1
  200.     jsr    _LVOCloseLibrary(a6)
  201.     clr.l    cybbase(a5)
  202.  
  203.     movem.l    (sp)+,a0
  204.     rts
  205.  
  206.  
  207.  
  208. drv_OpenScreen:
  209.     movea.l a0,a5
  210.  
  211.     move.l    screendim(a0),ScrDisplayID
  212.  
  213.     move.w    (a1)+,xsize(a5)
  214.     move.w    (a1)+,ysize(a5)
  215.     move.l    (a1)+,palette(a5)
  216.  
  217.     move.l    4.w,a6
  218.     lea    cyblib(pc),a1
  219.     moveq    #40,d0
  220.     jsr    _LVOOpenLibrary(a6)
  221.     move.l    d0,cybbase(a5)
  222.     beq.w    e0
  223.  
  224.     move.w    xsize(a5),cybwidth+2
  225.     move.w    ysize(a5),cybheight+2
  226.  
  227.     tst.l    ScrDisplayID
  228.     bne.b    modeisready
  229.  
  230.     moveq    #$00,d0
  231.     moveq    #$00,d1
  232.     move.w    xsize(a5),d0
  233.     move.w    ysize(a5),d1
  234.  
  235.     lea    cybmodetags(pc),a0
  236.     move.l    cybbase(a5),a6
  237.     jsr    _LVOBestCModeIDTagList(a6)
  238.     move.l    d0,ScrDisplayID
  239.  
  240. modeisready:
  241.     move.l    4.w,a6
  242.     move.l    #MEMF_PUBLIC,d1
  243.     move.l    #128*3*4+8,d0
  244.     JSRLIB    AllocVec
  245.     move.l    d0,palette32(a5)    ;Convert palette to 32 bit per gun
  246.     beq.w    e1
  247.     movea.l    d0,a0
  248.         move.l    palette(a5),a1
  249.     move.w    #128,(a0)+
  250.     move.w    #$0,(a0)+
  251.     move.l    #128*3-1,d2
  252. e2    moveq.l    #0,d0
  253.     move.b    (a1)+,d0
  254.     swap    d0
  255.     asl.l    #8,d0
  256.     move.l    d0,(a0)+
  257.     dbf    d2,e2
  258.     move.l    #0,(a0)
  259.     move.w    xsize(a5),width+2
  260.     move.w    ysize(a5),height+2
  261.     move.l    palette32(a5),pal
  262.  
  263.         suba.l    a0,a0            ;No newscreen stuct
  264.         lea    scrtags,a1
  265.     movea.l    intuibase(a5),a6
  266.     JSRLIB    OpenScreenTagList
  267.  
  268.     move.l    d0,wscr
  269.     move.l    d0,myscr(a5)
  270.     beq.b    e1
  271.  
  272.  
  273.     move.l    d0,a1
  274.     lea    sc_RastPort(a1),a1
  275.     move.l    rp_BitMap(a1),a0
  276.     lea    cgfxlocktags(pc),a1
  277.     move.l    cybbase(a5),a6
  278.     jsr    _LVOLockBitMapTagList(a6)    ;d0 = lock
  279.  
  280.     move.l    gfxboarddirectmem(pc),emuscr(a5)
  281.     
  282.     move.l    d0,a0                ;bitlock
  283.     jsr    _LVOUnLockBitMap(a6)
  284.  
  285.     movea.l    intuibase(a5),a6
  286.     move.w    xsize(a5),wwidth+2
  287.     move.w    ysize(a5),wheight+2
  288.     suba.l    a0,a0
  289.     lea    wintags,a1
  290.     JSRLIB    OpenWindowTagList
  291.     move.l    d0,mywin(a5)
  292.     beq.b    e1
  293.     movea.l    d0,a1
  294.  
  295.     move.l  wd_UserPort(a1),d0        ;IDCMP port
  296.     move.l    emuscr(a5),d2            ;chunky buffer
  297.     move.l    GfxBoardBitmapWidth(pc),d3    ;modulo (CV64 miatt ez az egyeduli korrekt mod)
  298.  
  299.     sub.w    xsize(a5),d3            ;modulo fix
  300.     
  301. e0:    move.l    #err_cyblib,d1
  302.     rts
  303.  
  304.  
  305. e1    move.l    #err_noscr,d1
  306.     rts
  307.  
  308. drv_CloseScreen:
  309.  
  310.     move.l    a0,a5
  311.     
  312.     tst.l    cybbase(a5)
  313.     beq.b    nemcyb
  314.     move.l    (4).w,a6
  315.     move.l    cybbase(a5),a1
  316.     jsr    _LVOCloseLibrary(a6)
  317.     clr.l    cybbase(a5)
  318.  
  319. nemcyb:    move.l    intuibase(a5),a6
  320.     move.l    mywin(a5),a0
  321.     cmp.l    #0,a0
  322.     beq.b    f1
  323.     JSRLIB    CloseWindow
  324.  
  325. f1    move.l    myscr(a5),a0
  326.     cmp.l    #0,a0
  327.     beq.b    f2
  328.     JSRLIB    CloseScreen
  329.  
  330. f2    movea.l    palette32(a5),a1
  331.         cmp.l    #0,a1
  332.     beq.b    f3
  333.     move.l    4.w,a6
  334.     JSRLIB    FreeVec        ;Deallocate translated palette
  335.  
  336. f3:    move.l    d0,emuscr(a5)    ;They were already freed
  337.     move.l    d0,palette32(a5)
  338.     move.l    d0,myscr(a5)
  339.     move.l    d0,mywin(a5)
  340.  
  341.     rts
  342.  
  343. drv_Refresh:
  344.  
  345.     move.l    emuscr(a0),d0
  346.         RTS
  347.  
  348. ;*** Constants
  349.  
  350.  
  351. cyblib:        dc.b    "cybergraphics.library",0
  352.  
  353.  
  354. scrtags:
  355.     dc.l    SA_Width
  356. width:    dc.l    0
  357.     dc.l    SA_Height
  358. height:    dc.l    0
  359.     dc.l    SA_Depth,8
  360.     dc.l    SA_Colors32
  361. pal:    dc.l    0
  362.     dc.l    SA_Title,scrtitle
  363.     dc.l    SA_ShowTitle,FALSE
  364.     dc.l    SA_DisplayID
  365.  
  366. ScrDisplayID:
  367.     dc.l    0
  368.  
  369.     dc.l    SA_Type,CUSTOMSCREEN
  370.     dc.l    SA_AutoScroll,TRUE
  371.     dc.l    SA_Overscan,OSCAN_STANDARD
  372.     dc.l    SA_Quiet,TRUE
  373.     dc.l    TAG_DONE
  374.  
  375. wintags:
  376.     dc.l    WA_Left,0
  377.     dc.l    WA_Top,0
  378.     dc.l    WA_Width
  379. wwidth:    dc.l    0
  380.     dc.l    WA_Height
  381. wheight:    dc.l    0
  382.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  383.     dc.l    WA_Title,0
  384.     dc.l    WA_Backdrop,TRUE
  385.     dc.l    WA_RMBTrap,TRUE
  386.     dc.l    WA_Borderless,TRUE
  387.     dc.l    WA_NoCareRefresh,TRUE
  388.     dc.l    WA_CustomScreen
  389. wscr:    dc.l    0
  390.     dc.l    WA_SimpleRefresh,TRUE
  391.     dc.l    WA_Activate,TRUE
  392.     dc.l    TAG_DONE
  393.  
  394. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  395.         EVEN
  396.  
  397. configfile:    dc.b    'cgfx.cfg',0
  398.         EVEN
  399.         
  400. cybmodetags:
  401.         dc.l    CYBRBIDTG_Depth,8
  402.         dc.l    CYBRBIDTG_NominalWidth
  403. cybwidth:    dc.l    0        
  404.         dc.l    CYBRBIDTG_NominalHeight
  405. cybheight:    dc.l    0
  406.         dc.l    TAG_END
  407.  
  408.  
  409. cgfxlocktags:    dc.l    LBMI_BASEADDRESS
  410.         dc.l    gfxboarddirectmem
  411.         dc.l    LBMI_BYTESPERROW
  412.         dc.l    GfxBoardBitmapWidth    
  413.  
  414.         dc.l    TAG_END
  415.  
  416. gfxboarddirectmem:
  417.         dc.l    0
  418. GfxBoardBitmapWidth:
  419.         dc.l    0
  420.  
  421. cybreqtags:    
  422.         dc.l    CYBRMREQ_MinWidth
  423. cgfxmodewidth:    dc.l    0        
  424.         dc.l    CYBRMREQ_MinHeight
  425. cgfxmodeheight:    dc.l    0
  426.         dc.l    CYBRMREQ_MinDepth
  427. cgfxmodedepth:    dc.l    8
  428.         dc.l    CYBRMREQ_MaxDepth
  429. cgfxmaxdepth:    dc.l    8
  430.         dc.l    CYBRMREQ_CModelArray
  431. cgfxpixform:    dc.l    cybreqcolors256
  432.         dc.l    TAG_END
  433.  
  434. cybreqcolors256:
  435.         dc.l    PIXFMT_LUT8
  436.         dc.l    TAG_END
  437.  
  438.  
  439. ;*** Errors
  440.  
  441. err_nomem:
  442.     dc.b    'Ran out of memory',0
  443. err_noscr:
  444.     dc.b    'Cannot open screen',0
  445. err_cyblib:
  446.     dc.b    'Cannot open cybergraphics.library v40+',0
  447.  
  448.